package com.bookcloud.java21.chapter6.嵌套接口66;

public class OuterClass {
  // 公共嵌套接口
  public interface PublicNestedInterface {
    void publicMethod();
  }

  // 受保护的嵌套接口
  protected interface ProtectedNestedInterface {
    void protectedMethod();
  }

  // 包级嵌套接口
  interface PackageNestedInterface {
    void packageMethod();
  }

  // 私有嵌套接口（Java 9+）
  private interface PrivateNestedInterface {
    void privateMethod();
  }

  // 实例公共嵌套接口
  private class PublicNestedClass implements PublicNestedInterface {
    @Override
    public void publicMethod() {
      System.out.println("公共嵌套接口方法实现");
    }
  }

  // protected 受保护的嵌套接口
  private class ProtectedNestedClass implements ProtectedNestedInterface {
    @Override
    public void protectedMethod() {
      System.out.println("受保护的嵌套接口方法实现");
    }
  }

  // 实现私有嵌套接口的内部类
  private class InnerClass implements PrivateNestedInterface {
    @Override
    public void privateMethod() {
      System.out.println("私有嵌套接口方法实现");
    }
  }

  // 外部调用公共嵌套接口
  public void testPublicInterface() {
    PublicNestedClass publicNested = new PublicNestedClass();
    publicNested.publicMethod();
  }

  // 外部调用受保护的嵌套接口
  public void testProtectedInterface() {
    ProtectedNestedClass protectedNested = new ProtectedNestedClass();
    protectedNested.protectedMethod();
  }

  public void testPrivateInterface() {
    InnerClass inner = new InnerClass();
    inner.privateMethod();
  }
}
